package top.someapp.applib.kits;

/**
 * null值检查工具类
 *
 * @author zwz
 * Created on 2020-04-01
 */
public class Nulls {

    private Nulls() {
        // no need instance.
    }

    public static boolean isNull(Object obj) {
        return null == obj;
    }

    public static boolean isNotNull(Object obj) {
        return !isNull(obj);
    }

    public static <T> boolean isAllNull(T... ts) {
        if (ts == null || ts.length == 0) {
            return true;
        }
        for (T t : ts) {
            if (isNotNull(t)) {
                return false;
            }
        }
        return true;
    }

    public static <T> T firstNonNull(T... ts) {
        if (ts == null || ts.length == 0) {
            return null;
        }
        for (T t : ts) {
            if (t != null) {
                return t;
            }
        }
        return null;
    }

    public static <T> T ifNull(T value, T valueIfNull) {
        return isNull(value) ? valueIfNull : value;
    }
}
